#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2022/5/20 10:57
# @Author    :cjw
import logging
from selenium.webdriver.common.by import By

from web_wework.page.base_page import BasePage


class AddDepartmentPage(BasePage):
	"""添加部门页面"""

	__INPUT_DEPARTMENT = (By.NAME, 'name')  # “部门名称”输入框
	__BTN_SELECT_DEPARTMENT = (By.XPATH, '//span[text()="选择所属部门"]')  # “选择所属部门”按钮
	__BTN_TEST_DEPARTMENT = (By.XPATH, '//div[@class="inputDlg_item"]//a[text()="测试部"]')  # 选择“测试部”部门
	__BTN_SUBMIT = (By.XPATH, '//a[text()="确定"]')  # “确定”按钮
	__TEXT_TIPS = (By.ID, 'js_tips')  # 冒泡信息

	def add_department(self, name: str):
		"""
		添加部门
		:param name: 部门名称
		:return:
		"""
		from web_wework.page.contact_page import ContactPage

		# 输入部门名称，创建部门
		logging.info(f'填写部门信息，部门名称：{name}, 部门：测试部')
		self.send_keys(self.__INPUT_DEPARTMENT, name)
		self.click(self.__BTN_SELECT_DEPARTMENT)
		self.click(self.__BTN_TEST_DEPARTMENT)
		self.click(self.__BTN_SUBMIT)
		return ContactPage(self.driver)

	def add_department_fail(self, name: str, is_select_department: bool = True):
		"""
		添加部门失败
		:param name: 部门名称
		:param is_select_department: 是否选择部门
		:return:
		"""
		# 输入部门名称，创建部门
		logging.info(f'填写部门信息，部门名称：{name}, 部门：测试部')
		self.send_keys(self.__INPUT_DEPARTMENT, name)
		if is_select_department:
			self.click(self.__BTN_SELECT_DEPARTMENT)
			self.click(self.__BTN_TEST_DEPARTMENT)
		self.click(self.__BTN_SUBMIT)
		tip_text = self.find(self.__TEXT_TIPS).text
		return tip_text
